<div class="head">
	<div class="actions"><?php 
		echo $html->image('add.gif');
		echo ' ';
		echo $html->link( __('Add new Contact', true), array(
			'action'=>'add', 'kind'=>(isset($params['kind'])?$params['kind']:'T'),
			'time'=>time()
		)); ?></div>
	<h2><?php __('Contacts'); ?></h2>
	<div class="filter">
		<?php
			echo $form->create(false, array('url'=>array('action'=>'index')));
		?>
			<a href="#">Filter</a>: <a href="#">all</a> <a href="#">persons</a> matching
		<?php
			echo $form->input('search', array('label'=>false, 'div'=>false, 'value'=>@$params['search']));
			echo $form->submit(__('OK', true), array('div'=>false, 'class'=>'search'));
			echo $form->end();
		?>
	</div>
</div>
<?php //echo $this->element('contacts/subnav'); ?>
<div class="index">
	<?php
		if (sizeof($contacts)==0) {
	?>
		<p><?php __('Ups. No contacts found.'); ?></p>
		<br />
	<?php
		} else {
	?>
	<table cellpadding="0" cellspacing="0" id="ContactsIndexTable">
		<thead>
			<tr>
				<th>&nbsp;</th>
				<th class="left"><?php echo $paginator->sort(($params['kind']=='T')?__('Name', true):__('Title', true), 'title');?></th>
				<th class="left"><?php __('Email'); ?></th>
				<th class="left"><?php __('Phone'); ?></th>
				<th class="actions">&nbsp;</th>
			</tr>
		</thead>
		<?php 
			$i = 1;
			foreach ($contacts as $contact) {
		?>
		<tr<?php if($i++%2==0) echo ' class="altrow"'; ?>>
			<td width="32">
				<?php
					if (file_exists(IMAGES.DS.'contacts'.DS.$contact['Contact']['id'].'.gif')) {
						echo $html->image('contacts/'.$contact['Contact']['id'].'.gif', array('style'=>'width:32px'));
					} else { 
						echo $html->image('/img/'.ife($params['kind']=='T', 'person.gif', 'company.gif'), array('style'=>'width:32px'));
					}
				?>
			</td>
			<td>
				<?php
					echo $html->link($contact['Contact']['title'], 
						array('action'=>'view', $contact['Contact']['id'], strtotime($contact['Contact']['modified'])), array('class' => 'big'));
					
					if (!empty($contact['Contact']['company_id'])) {
						echo '<br />';
						if ( !empty($contact['Contact']['job'])) {
							echo h($contact['Contact']['job']);
						} else {
							echo '<span class="light">'.__('employed', true).'</span>';
						}
						echo ' <span class="light">'.__('at', true).'</span> ';
						echo $html->link($contact['Company']['title'], 
							array('action'=>'view', $contact['Company']['id'], strtotime($contact['Company']['modified'])));
					} else if (!empty($contact['Contact']['job'])) {
						echo '<br />';
						echo h($contact['Contact']['job']);
					}
				?>
			</td>
			<td>
				<?php
					if (!empty($contact['Email']) && is_array($contact['Email']))
						foreach ($contact['Email'] as $email) {
							echo $html->link($email['email'], 'mailto:'.h($email['email'])) . ' <span class="small">' . $GLOBALS['email_types'][$email['kind']] .'</span><br />';
						}
					else echo "&nbsp;";
				?>
			</td>
			<td>
				<?php
					if (!empty($contact['Phone']) && is_array($contact['Phone']))
						foreach ($contact['Phone'] as $phone) {
							echo '<span class="strong">' . h($phone['no']) . '</span> <span class="small">' . $GLOBALS['phone_types'][$phone['kind']] .'</span><br />';
						}
					else echo "&nbsp;";
				?>
			</td>
			<td class="actions">
				<?php echo $html->link(__('view',true), array('action'=>'view', $contact['Contact']['id'])); ?>
				<?php echo $html->link(__('Edit',true), array('action'=>'edit', $contact['Contact']['id'])); ?>
				<?php echo $html->link(__('Delete',true), array('action'=>'delete', $contact['Contact']['id']), null, __('Are you sure you want to delete contact #',true) . $contact['Contact']['id']); ?>
			</td>
		</tr>
		<?php } ?>
		<tfoot>
			<tr>
				<td colspan="6" class="paging">
					<?php echo $paginator->prev('<< '.__('previous', true), array('class'=>'prev'), null, array('class'=>'prev light'));?>
					<?php echo $paginator->next(__('next', true).' >>', array('class'=>'next'), null, array('class'=>'next light'));?>
					<?php
						echo '<div class="counter">'.$paginator->counter(array(
						'format' => __('Page <b>%page%</b> of <b>%pages%</b>, total <b>%count%</b> records.', true))).'</div>';
					?>
					
				</td>
			</tr>
		</tfoot>
	</table>
	<script type="text/javascript">
		$(document).ready( function() {
			$("#ContactsIndexTable td.actions, #ContactsIndexTable th.actions").hide();
			
			$("#ContactsIndexTable tbody tr").mouseover( function() {
				$(this).addClass("highlight");
			}).mouseout( function() {
				$(this).removeClass("highlight");
			}).click( function() {
				window.location.href = $(this).children("td.actions").children(0).attr('href');
			});

		});
	</script>
	<?php
		} // sizeof($contacts)==0
	?>
</div>